﻿// 代理设计模式:为其他对象提供一种代理。以控制对这个对象的访问。
/*代理模式一般又分为安全代理，虚拟代理 ，远程代理*/
Console.WriteLine("代理设计模式");

ClassFlower classFlower = new ClassFlower("韩梅梅");
RealLaoWang realLaoWang=new RealLaoWang(classFlower);
Proxy proxy=new Proxy(realLaoWang);
ISubject subject = proxy;
subject.GiveBeer();
subject.GiveJK();
subject.GiveSmoking();  
public class ClassFlower
{
    public string  Name { get; set; }
    public ClassFlower(string name)
    {
        Name=name;
    }
}
/// <summary>
/// 不管是代理还是十几人都需要做的共同动作
/// </summary>
public interface ISubject
{
    void GiveSmoking();
    void GiveBeer();
    void GiveJK();
}
/// <summary>
/// 实际人
/// </summary>
public class RealLaoWang : ISubject
{
    private readonly ClassFlower _classFlower;

    public RealLaoWang(ClassFlower classFlower)
    {
        _classFlower = classFlower;
    }
    public void GiveBeer()
    {
        Console.WriteLine($"{_classFlower.Name}:请你喝酒");
    }

    public void GiveJK()
    {
        Console.WriteLine($"{_classFlower.Name}:请你穿JK");
    }

    public void GiveSmoking()
    {
        Console.WriteLine($"{_classFlower.Name}:请你抽烟");
    }
}
/// <summary>
/// 代理人
/// </summary>
public class Proxy : ISubject
{
    private readonly RealLaoWang _realLaoWang;

    public Proxy(RealLaoWang realLaoWang)
    {
        _realLaoWang = realLaoWang;
    }
    public void GiveBeer()
    {
        _realLaoWang.GiveBeer();
    }

    public void GiveJK()
    {
        _realLaoWang.GiveJK();
    }

    public void GiveSmoking()
    {
        _realLaoWang.GiveSmoking();
    }
}